﻿using System;
using System.Collections.ObjectModel;

namespace AppGene.DataModel
{
    /// <summary>
    /// The class provides a description for logical index.
    /// </summary>
    /// <remarks>
    /// Default, a logical index is an unique, non-cluster index. 
    /// Users need not to set the index name explicitly, 
    /// the name will be generated automatically when the name is not provided.
    /// </remarks>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
    public class LogicalIndexAttribute
        : Attribute
    {
        /// <summary>
        /// Creates an index instance.
        /// </summary>
        private LogicalIndexAttribute()
        {
            IsClustered = true;
            IsUnique = true;
        }

        /// <summary>
        /// Creates an index instance.
        /// </summary>
        /// <param name="column">The column name of index.</param>
        public LogicalIndexAttribute(string column)
            : this(new string[] { column })
        { }

        /// <summary>
        /// Creates an index instance.
        /// </summary>
        /// <param name="column">The column name of index.</param>
        /// <param name="column2">The second column name of index.</param>
        public LogicalIndexAttribute(string column, string column2)
            : this(new string[] { column, column2 })
        { }

        /// <summary>
        /// Creates an index instance.
        /// </summary>
        /// <param name="columns">The columns' names for the index.</param>
        public LogicalIndexAttribute(string[] columns)
            : this()
        {
            this.Columns = new ReadOnlyCollection<string>(columns);
        }

        /// <summary>
        /// Gets the column collection for the index.
        /// </summary>
        public ReadOnlyCollection<string> Columns { get; private set; }

        /// <summary>
        /// Indicate if the index is a cluster index. Default is true.
        /// </summary>
        public bool IsClustered { get; set; }

        /// <summary>
        /// Indicates if the index is an unique index. Default is true.
        /// </summary>
        public bool IsUnique { get; set; }

        /// <summary>
        /// Gets the index name.
        /// </summary>
        public string Name { get; set; }
    }
}
